

let mixins={
   mounted() {

   },
   data() {
      return {
            initdata:{},
        }
   },
   methods: {
    close(){
        window.location.href = 'closeLicaiShiPage'
    },
     appgetdata(res){
        let _this=this
        if (typeof res !='object') {
            _this.initdata=eval('(' + res + ')')
          }else{
            _this.initdata=res
          }   

         setTimeout(()=>{
             
             if (_this.initdata.type==0) {
                let data={
                     key:[],
                     singledata:[],
                     compounddata:[]
                }

                _this.initdata.singleCompoundIncome.data.map((item=>{
                       data.key.push(item.year)
                       data.singledata.push(item.singleIncome)
                       data.compounddata.push(item.compoundIncome)
                }))

                _this.drawtwoline('myLine',data)
             }
             if ( _this.initdata.type==1) {
                let data={}
                 data.title=['总投入','总收入']
                data.key=[_this.initdata.income.totalInvestment,_this.initdata.income.totalInvestment,_this.initdata.income.totalInvestment]
                data.value= [_this.initdata.income.fixedMonthInvestment.fixed,_this.initdata.income.fixedMonthInvestment.totalIncome,_this.initdata.income.fixedMonthInvestment.totalIncome]
                _this.initpie('pieCon',data)
             }
             if ( _this.initdata.type==2) {
                let data={}
                data.title=['总投入','目标金额']
                data.key=[_this.initdata.investment.oneInvestment.totalInvestment,_this.initdata.investment.fixedInvestment.totalInvestment,_this.initdata.investment.fixedMonthInvestment.totalInvestment]
                data.value=[_this.initdata.investment.totalIncome,_this.initdata.investment.totalIncome,_this.initdata.investment.totalIncome]
                _this.initpie('pieCon2',data)
            }
            
         })

      },
      initpie(id,data){
       var _this=this
        var pie = document.getElementById(id); 
        var chartsModel = echarts.init(pie)
       var typeName=null
        if (_this.type==0) {
            typeName='一次性投入'
        }
        if (_this.type==1) {
           typeName='月定投'
       }
       if (_this.type==2) {
           typeName='年定投'
       }

        var option = {
           title: {
               text: '单位：元',
               textStyle:{
                   fontSize: 13,
               },
               top:20
           },
           legend: {},
           tooltip: {},
           dataset: {},
           xAxis: {
               type: 'category',
               axisTick:{       //x轴刻度线
                   show:false
               },
               data:[`一次性投资`,`每年定投`,`每月定投`]
           },
           yAxis: {
               type: 'value',
               axisLine:{
                   show:false
               },
               axisTick:{       //y轴刻度线
                   show:false
               },
               axisLabel:{
                   show:false
               },
               splitLine:{
                   show:false
               },
              
           },
           // Declare several bar series, each will be mapped
           // to a column of dataset.source by default.
           series: [
               {
                   type: 'bar',
                   data:data.key,
                   name:data.title[0],
                   itemStyle :{
                       normal: {
                           label: {
                               show: true,
                               position: 'top', //柱子上方显示 数值
                               // formatter: '{c}' //数值加上'%'
                           },
                           color: '#2EC7C9'
                       }
                   }
               },
               {
                   type: 'bar',
                   data:data.value ,
                   name:data.title[1],
                   itemStyle :{
                       normal: {
                           label: {
                               show: true,
                               position: 'top', //柱子上方显示 数值
                               // formatter: '{c}' //数值加上'%'
                           },
                           color: '#5AB1EF'
                       }
                   }
               },     
           ]
       };
       
        chartsModel.setOption(option);
        window.onresize = function () {
            chartsModel.resize();
        } 
    },
    drawtwoline(id,data){
        let _this=this
         // 基于准备好的dom，初始化echarts实例
         let myChart =echarts.init(document.getElementById(id))
         // 绘制图表
         myChart.setOption({
             title: {
                 text: ''
             },
             tooltip: {
                 trigger: 'axis'
             },
             legend: {
                 data:['单利','复利']
             },
                 xAxis: {
                     type: 'category',
                     data:data.key
                 },
                 yAxis: {
                     type: 'value',
                      axisTick: {
                         show: false
                     },//隐藏刻度线
                     axisLine : {onZero: false,show:false},//隐藏y轴，
                     splitLine:{
                 　　　　show:true
                 　　 }
                     
                 },
                 series:[
                    {
                        name:'单利',
                        type:'line',
                        stack: '总量',
                        data:data.singledata
                    },
                    {
                        name:'复利',
                        type:'line',
                        stack: '总量',
                        data:data.compounddata
                    },
            
                 ]
             });
     },
   },

}




